import config from "@/config/config.js";
import http from "@/api/http.js";


const IncomingRequest={
    loadIncoming(incoming,page=1,limit=10,callBack){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.defectBaseUrl + "/incoming/list?page="+page + "&limit="+limit;
            if(incoming){
                if (incoming.incomingId){
                    url += "&incomingId=" + incoming.incomingId;
                }
                if(incoming.incomingName){
                    url += "&incomingName=" + incoming.incomingName;
                }
                if (incoming.vendorName){
                    url += "&vendorName=" + incoming.vendorName;
                }
                if (incoming.vendorNumber){
                    url += "&vendorNumber=" + incoming.vendorNumber;
                }
                if (incoming.materialNumber){
                    url += "&materialNumber=" + incoming.materialNumber;
                }
                if (incoming.materialName){
                    url += "&materialName=" + incoming.materialName;
                }
                if (incoming.receptionNumber){
                    url += "&receptionNumber=" + incoming.receptionNumber;
                }
                if (incoming.testNumber){
                    url += "&testNumber=" + incoming.testNumber;
                }
                if (incoming.unqualifiedNumber){
                    url += "&unqualifiedNumber=" + incoming.unqualifiedNumber;
                }
                if (incoming.incomingResult){
                    url += "&incomingResult=" + incoming.incomingResult;
                }
                if (incoming.createTime){
                    url += "&createTime=" + incoming.createTime;
                }
                if (incoming.testTime){
                    url += "&testTime=" + incoming.testTime;
                }
                if (incoming.Inspectors){
                    url += "&Inspectors=" + incoming.Inspectors;
                }
                if (incoming.incomingStatus){
                    url += "&incomingStatus=" + incoming.incomingStatus;
                }
            }
            http.get(url,callBack);
        }else {
            callBack(undefined);
        }
    },
    saveIncoming(incoming,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.defectBaseUrl + "/incoming/save";
            http.post(url,incoming,callBack);
        }else {
            callBack(undefined);
        }
    },
    updateIncomingById(incoming,callBack) {
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.defectBaseUrl + "/incoming/update";
            http.put(url,incoming,callBack);
        } else {
            callBack(undefined);
        }
    },
    selectById(incomingId,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.defectBaseUrl + "/incoming/get?incomingId=" + incomingId;
            http.get(url,callBack);
        }else {
            callBack(undefined);
        }
    },
    export(incoming,page=1,limit=10,callBack){
        let token = localStorage.getItem("token");
        if (token){
            let url = config.defectBaseUrl + "/incoming/export?page=" + page + "&limit=" + limit;
            http.get(url,callBack);
        }else {
            callBack(undefined);
        }
    },



}

export default IncomingRequest